﻿class Block extends MovieClip
{
	private var my_acceln:Number;
	private var my_mass:Number = 1;
	private var my_angle:Number;
	private var my_grav:Number = 0.9;
	private var my_fricn:Number = 0.9;
	
	private var x_loc:Number;//containers for a snapshot of the original location
	private var y_loc:Number;
	
	function Block()
	{
		x_loc = _x; //initialise
		y_loc = _y;
		
		onEnterFrame = function()
		{
			var movement:Number = calc_attraction();
			move_unit(movement); //process attraction effect
			scale_unit(); //change size according to distance
		}
	}
	public function set angle(ang:Number):Void
	{
		my_angle = ang;
	}
	public function set acceleration(a:Number):Void
	{
		my_acceln = a;
	}
	private function calc_attraction(Void):Number
	{
		my_acceln *= my_fricn; //deceleration accounting for friction
		var force:Number = my_mass * my_acceln; //calculate outgoing force
		//trace(force);
		//var opp_force:Number = my_grav * get_distance(); //function of distance
		var opp_force:Number = 20.5;
		var attraction:Number = force - opp_force; //take away effect of gravity
		return (attraction);//return the influence of the attractor (source of gravity)
	}
	private function move_unit(val:Number):Void
	{
		this._x += val * Math.cos(my_angle); // move object
		this._y += val * Math.sin(my_angle);
	}
	private function get_distance(Void):Number
	{
		return (Math.sqrt(Math.pow((_x - x_loc),2) + Math.pow((_y - y_loc),2) ) );
	}
	private function scale_unit(Void):Void
	{
		this._yscale = this._xscale = 0.8 * -get_distance() + 100;
	}
}